// custom-tab-bar/index.js
import { createStoreBindings, storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/store'
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [storeBindingsBehavior],

  storeBindings:{
    store,
    fields:{
      active:'activeTabBarIndex'
    },
    actions:{
      updateActive:'updateActiveTabBarIndex'
    }
  },
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    "list": [
      {"pagePath": "/pages/home/home",
      "iconPath": "/images/icons/home.png",
    "selectedIconPath": "/images/icons/home.png"},
      {"pagePath": "/pages/health/health",
      "iconPath": "/images/icons/health.png",
    "selectedIconPath": "/images/icons/health.png"},
      {"pagePath": "/pages/voice/voice",
      "iconPath": "/images/icons/voice.png",
    "selectedIconPath": "/images/icons/voice.png"},
      {"pagePath": "/pages/navigation/navigation",
      "iconPath": "/images/icons/navigation.png",
    "selectedIconPath": "/images/icons/navigation.png"},
      {"pagePath": "/pages/me/me",
      "iconPath": "/images/icons/me.png",
    "selectedIconPath": "/images/icons/me.png"}
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      //this.setData({ active: event.detail });
      this.updateActive(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})